<template>
  <div class="wrapper">

    <div class="fabu_item">

      <div class="order-field" style="margin-top: 10px;">
        <span class="field-label">开始日期:</span>
        <span class="field-value">{{ Order.startDate }}</span>
      </div>
      <div class="order-field">
        <span class="field-label">结束日期:</span>
        <span class="field-value">{{ Order.endDate }}</span>
      </div>
      <div class="order-field">
        <span class="field-label">薪&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;酬:</span>
        <span class="field-value">{{ Order.salary }}</span>
      </div>
      <div class="order-field">
        <span class="field-label">年&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;级:</span>
        <span class="field-value">{{ Order.grade }}</span>
      </div>
      <div class="order-field">
        <span class="field-label">科&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;目:</span>
        <span class="field-value">{{ Order.subject }}</span>
      </div>
      <div class="order-field">
        <span class="field-label">要&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;求:</span>
        <span class="field-value">{{ Order.demand }}</span>
      </div>
      <div class="order-field">
        <span class="field-label">城&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;市:</span>
        <span class="field-value">{{ Order.shi }}</span>
      </div>
      <div class="order-field">
        <span class="field-label">区&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;县:</span>
        <span class="field-value">{{ Order.xian }}</span>
      </div>
      <div class="order-field" style="margin-bottom: 10px;">
        <span class="field-label">街&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;道:</span>
        <span class="field-value">{{ Order.street }}</span>
      </div>
    </div>
    <div class="butt" @click="closeRenwu(Order.id)">
      取消任务
    </div>
    <div class="applayer">
      <div class="tit">
        任务申请信息:
      </div>
      <div class="applayer-item">
        <div class="item" v-for="item in applays">
          <img :src="`${this.ipAddress}/file/getPortrait/${item.tutor}`" alt="" class="ptt">
          <div class="username" @click="ApplayUserDetail(item.tutor)">
            <span>申请人:</span><br>
            <div class="zhanghao">{{ item.tutor }}</div>
          </div>
          <div class="but-jujue" @click="rejectApplay(item.tutor)">拒绝</div>
          <div class="but-tongyi" @click="agreeApplay(item.tutor)">同意</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Order from '../Order.vue';
import axios from 'axios';
import settings from '../../../settings.json'
import { setStatusBarColor } from "tauri-plugin-status-bar-color-api";
import ApplayUserDetail from './ApplayUserDetail.vue';
export default {
  name: "Test",
  created() {
    this.ipAddress = settings.ipAddress
    let id = this.$route.query.id;
    axios.get(settings.ipAddress + `/order/getOrderById/${id}`).then(res => {
      this.Order = res.data;
      console.log(res.data);
    }).catch(err => {
      console.log(err);
    });
    this.getApplays()
  },
  data() {
    return {
      Order: null,
      applays: null,
      ipAddress: ''
    };
  },
  props: {},
  methods: {
    async getOrders() {
      try {
        const tutor = 'tutorValue';
        const response = await axios.get(settings.ipAddress + `/order/byParentAndValid`,
          {
            params: {
              parent: this.user.username,
            }
          }
        );
        this.Order = response.data;
        console.log(response.data);
      } catch (error) {
        console.error('Error selecting by tutor and start date after now:', error);
      }
    },
    getApplays() {
      axios.get(settings.ipAddress + `/applay/selectByOid`,
        {
          params: {
            oid: this.$route.query.id,
          }
        }
      ).then(res => {
        console.log("hhhhhh");
        this.applays = res.data
        console.log(res.data)
      })
    },
    ApplayUserDetail(tutor) {
      this.$router.push({ path: '/applayUserDetail', query: { username: tutor } })
    },
    agreeApplay(tutor) {
      axios.get(settings.ipAddress + `/order/orderSuccess`,
        {
          params: {
            id: this.$route.query.id,
            tutor: tutor,
          }
        }
      ).then(res => {
        alert("兼职已同意，请在任务列表查看")
      })
    },
    rejectApplay(tutor) {
      axios.get(settings.ipAddress + `/order/orderFail`,
        {
          params: {
            id: this.$route.query.id,
            tutor: tutor,
          }
        }
      ).then(res => {
        alert("兼职已拒绝")
      })
    },
    closeRenwu(id) {
      axios.get(settings.ipAddress + `/order/quXiaoRenwu`,
        {
          params: {
            id: id,
          }
        }
      ).then(res => {
        alert("兼职已取消")
      })
    },
  },

};
</script>

<style lang="scss" scoped>
$primary-color: #ffffff;
$secondary-color: #E8F5E9;
$text-color: #333;
$border-color: #C8E6C9;

.wrapper {
  width: 100vw;
  height: calc(100vh - 30px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  top: 30px;
  position: fixed;

  .fabu_item {
    padding-top: 5px;
    padding-bottom: 5px;
    border-bottom: 1px solid $border-color;
    width: 90vw;
    height: fit-content;
    margin-top: 10px;
    margin-left: 5vw;
    margin-bottom: 10px;
    background-color: #dee6d8;
    border-radius: 4px;

    &:last-child {
      border-bottom: none;
    }

    .order-field {
      span {
        border-bottom: 0.1px solid #000;
      }

      // background-color: #5f5f5f;
      display: flex;
      flex-wrap: wrap;
      margin-top: 5px;
      margin-bottom: 5px;
      width: 84vw;
      max-width: 84vw;
      margin-left: 3vw;

      .field-label {
        flex: 0 0 30%;
        font-weight: bold;
        font-size: 13px;
        color: $text-color;
      }

      .field-value {
        flex: 0 0 70%;
        font-size: 13px;
        color: $text-color;
      }
    }


  }

  .applayer {
    height: 56vh;
    margin-top: 10px;
    background-color: #470808;
    width: 90vw;
    margin-bottom: 4vh;
    margin-left: 5vw;

    .tit {
      width: 100%;
      height: 29px;
      background-color: #fff;
      font-size: 18px;
      font-weight: bold;
      border-bottom: 1px solid #dee6d8;
    }

    .applayer-item {
      height: calc(100% - 30px);
      width: 100%;
      background-color: #fff;
      overflow: scroll;
      margin-bottom: 10px;

      .item {
        height: 50px;
        width: 100%;
        border-bottom: 1px solid #dee6d8;
        display: flex;
        align-items: center;
        margin-top: 5px;
        margin-bottom: 5px;

        img {
          height: 40px;
          width: 40px;
          border-radius: 50%;
        }

        .username {
          margin-left: 5px;
          font-size: 14px;
          width: 170px;

          // background-color: #6f6868;
          span {
            background-color: #fa7508;
            border-radius: 3px;
            color: #ffffff;
            font-size: 13px;
          }
        }

        .but-jujue {
          width: 50px;
          background-color: #75726f;
          text-align: center;
          height: 28px;
          line-height: 28px;
          border-radius: 4px;
          color: #ffffff;
        }

        .but-tongyi {
          width: 50px;
          height: 28px;
          text-align: center;
          background-color: #24f520;
          margin-left: 5px;
          line-height: 28px;
          border-radius: 4px;
          color: #ffffff;
        }
      }
    }

    .applayer-item::-webkit-scrollbar {
      display: none;
    }
  }

  .butt {
    margin-left: 35vw;
    width: 33vw;
    height: 30px;
    font-size: 18px;
    line-height: 30px;
    text-align: center;
    font-weight: bold;
    border-radius: 4px;
    color: #ffffff;
    background-color: #0276fb;
  }
}
</style>